import {getStorage, setStorage} from "hcg-storage";
import User from '@/services/user';

const _user = new User();
let token = getStorage('token') || '';
export default {
	state: {
		token,
		user: null,
		isLogin: false,
	},
	actions: {
		getUserDetail({commit}, token) {
			commit('setToken', token);
			commit('isLogin', true);
			setStorage('token', token);
			_user.getUserDetail(token).then(res => {
				commit('setUser', res.data.base);
			})
		}
	},
	mutations: {
		setToken(state, token) {
			state.token = token;
		},
		setUser(state, user) {
			state.user = user;
		},
		isLogin(state, status) {
			state.isLogin = status;
		}
	}
}
